#include "lab2_problem2a.h"

#include <cmath>
#include <iostream>

#include "../p1/bisection.h"

namespace Lab2
{
    namespace Problem2a
    {
        namespace
        {
            // Function to be used with bisection method
            double function(const double x) 
            { 
            	return tan(x) - 2.0 * x; 
            }
        }

        void problem2a()
        {
        	const double leftLimit = 0.8;
        	const double rightLimit = 1.4;
        	const double stopBound = 0.00001;

        	// Build input data
        	const NumericalAnalysis::BisectionInputData inputData(leftLimit, rightLimit, stopBound, function);
        	const NumericalAnalysis::BisectionOutputData outputData = NumericalAnalysis::BisectionMethod(inputData);

        	// Print information:
        	// Number of iterations = 16
        	// Solution = 1.16556
        	std::cout << "Lab 2 - Problem 2 A:" << std::endl;
        	std::cout << "Number of iterations = " << outputData.mApproximations.size() << std::endl;
        	std::cout << "Solution = " << outputData.mLastApproximation << std::endl;
        }    
    }
}
